cask 'mplab-xc8' do
  version '2.20'
  sha256 'e7471560a327b8ea573f4b7d9fdcd8faa504adce5a0d93242c18d85a121b6984'

  url "https://ww1.microchip.com/downloads/en/DeviceDoc/xc8-v#{version}-full-install-macos-installer.dmg"
  appcast 'https://macupdater.net/cgi-bin/check_urls/check_url_redirect.cgi?url=https://www.microchip.com/mplabxc8osx'
  name 'MPLab XC8 Compiler'
  homepage 'https://www.microchip.com/mplab/compilers'

  installer script: {
                      executable: "xc8-v#{version}-full-install-macos-x64-installer.app/Contents/MacOS/installbuilder.sh",
                      args:       [
                                    '--mode', 'unattended',
                                    '--unattendedmodeui', 'none',
                                    '--ModifyAll', '0',
                                    '--netservername', '""',
                                    '--LicenseType', 'FreeMode',
                                    '--prefix', staged_path.to_s
                                  ],
                      input:      ['y'],
                      sudo:       true,
                    }
  binary "#{staged_path}/bin/xc-ccov"
  binary "#{staged_path}/bin/xc8"
  binary "#{staged_path}/bin/xc8-ar"
  binary "#{staged_path}/bin/xc8-cc"
  binary "#{staged_path}/bin/xclm"

  postflight do
    set_ownership staged_path.to_s
  end

  uninstall script: {
                      executable: "Uninstall-xc8-v#{version}.app/Contents/MacOS/installbuilder.sh",
                      args:       ['--mode', 'unattended'],
                      sudo:       true,
                    }
end
